@extends('Admin.layouts.application')
@section('css')
    <link rel="stylesheet" href="/assets/xSystem/vendor/daterangepicker/daterangepicker.css">

@endsection
@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">视频分类管理</strong> /
                    <small>Video classification management</small>
                </div>
            </div>

            <hr>
            @include('Admin.layouts._flash')
            <div class="am-g" style="height: 37px;">
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a type="button" class="am-btn am-btn-success" href="{{route('videoCategory.create')}}">
                                <span class="am-icon-plus"></span> 新增分类
                            </a>
                            {{--<button type="button" class="am-btn am-btn-success" id="show_all"
                                    href="{{route('videoCategory.create')}}">
                                <span class="am-icon-arrows-alt"></span> 展开所有
                            </button>--}}
                        </div>
                    </div>
                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">

                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-id">编号</th>
             {{--                   <th class="table-thumb">缩略图</th>--}}
                                <th class="table-title">分类名</th>
                                {{--<th class="table-category">分类视频</th>--}}
                                <th class="table-brand">是否显示</th>
                                <th class="table-price">排序</th>
                                <th class="am-hide-sm-only">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($categories as $videocategory)
                                 <tr data-id="{{$videocategory->id}}" id="row_{{$videocategory->id}}" class="xParent">
                                    <td>{{$videocategory->id}}</td>
                                    {{--<td>
                                        @if($videocategory->thumb)<img width="100" height="50" src="{{$videocategory->thumb}}" alt="" class="thumb">@endif
                                    </td>--}}
                                    <td>
                                        {{ indent_category($videocategory->count) }}
                                        {{$videocategory->name}}
                                    </td>

                                     <td class="am-hide-sm-only">
                                         {!! is_something('is_show', $videocategory) !!}
                                     </td>

                                    <td class="am-hide-sm-only">
                                        <input  type="text" name="sort_order" class="am-input-sm"
                                                value="{{$videocategory->sort_order}}">
                                    </td>


                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                @if( $videocategory->id > 10)
                                                    <a class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                       href="{{route('videoCategory.edit', $videocategory->id)}}">
                                                        <span class="am-icon-pencil-square-o"></span> 编辑
                                                    </a>

                                                    <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                                       href="{{route('videoCategory.destroy', $videocategory->id)}}"
                                                       data-method="delete"
                                                       data-token="{{csrf_token()}}" data-confirm="确认删除吗?">
                                                        <span class="am-icon-trash-o"></span> 删除
                                                    </a>
                                                @endif

                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                {{--@foreach ($videocategory->children as $c)
                                    <tr data-id="{{$c->id}}" class="xChildren child_row_{{$videocategory->id}}" style="display: table-row;">
                                        <td>{{$c->id}}</td>
                                        --}}{{--<td>
                                            @if($c->thumb)<img width="100" height="50" src="{{$c->thumb}}" alt="" class="thumb">@endif
                                        </td>--}}{{--
                                        <td>
                                            {{ indent_category(2) }}
                                            {{$c->name}}
                                        </td>

                                        <td>
                                            {!! show_category_products($c) !!}
                                        </td>

                                        <td class="am-hide-sm-only">
                                            {!! is_something('is_show', $c) !!}
                                        </td>

                                        <td class="am-hide-sm-only">
                                            <input type="text" name="sort_order" class="am-input-sm"
                                                   value="{{$c->sort_order}}">
                                        </td>

                                        <td>
                                            <div class="am-btn-toolbar">
                                                <div class="am-btn-group am-btn-group-xs">
                                                    <a class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                       href="{{route('videoCategory.edit', $c->id)}}">
                                                        <span class="am-icon-pencil-square-o"></span> 编辑
                                                    </a>

                                                    <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                                       href="{{route('videoCategory.destroy', $c->id)}}"
                                                       data-method="delete"
                                                       data-token="{{csrf_token()}}" data-confirm="确认删除吗?">
                                                        <span class="am-icon-trash-o"></span> 删除
                                                    </a>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                @endforeach--}}
                            @endforeach
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
        @include('Admin.layouts._footer')

    </div>
@endsection

@section('js')

    <script src="/assets/xSystem/vendor/daterangepicker/moment.js"></script>
    <script src="/assets/xSystem/vendor/moment/locale/zh-cn.js"></script>
    <script src="/assets/xSystem/vendor/daterangepicker/daterangepicker.js"></script>

    <script src="/assets/xSystem/js/daterange_config.js"></script>
    <script>
        $(function () {
            //是否...
            $(".is_something").click(function () {
                var _this = $(this);
                var data = {
                    id: _this.parents("tr").data('id'),
                    attr: _this.data('attr')
                }
                console.log(data);
                $.ajax({
                    type: "PATCH",
                    url: "/videoCategory/is_something",
                    data: data,
                    success: function () {
                        _this.toggleClass('am-icon-close am-icon-check');
                    }
                });
            });

            //排序
            $("input[name='sort_order']").change(function () {
                var data = {
                    sort_order: $(this).val(),
                    id: $(this).parents("tr").data('id')
                };
                console.log(data);
                $.ajax({
                    type: "PATCH",
                    url: "/videoCategory/sort_order",
                    data: data,
                });
            });
            //展开与折叠表格
            $("tr.xParent").dblclick(function () {
                $(this).toggleClass('am-active');
                $(".child_" + this.id).toggle();
            });

            $("#show_all").click(function () {
                $("tr.xParent").toggleClass('am-active');
                $("tr.xChildren").toggle();
            });
        });
    </script>


@endsection





